package com.qinghuan.threads.chapterOne;

/**
 * @Author: dubao
 * @Date: 2022/5/17 20:16
 * @Description:
 */

/**
 * interrupted() 与 isInterrupted() 方法的不同
 * 调用interrupted()方法后中断标志被清除了（当发现当前线程被中断的时候才会这样）
 */
public class Test1_7_3 {

    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                for (;;) {

                }
            }
        });

        threadOne.start();
        //设置中断标志
        threadOne.interrupt();
        //获取中断标志
        System.out.println("isInterrupted:" + threadOne.isInterrupted());
        //获取中断标志并重置
        System.out.println("isInterrupted:" + threadOne.interrupted());
        //获取中断标志并重置
        System.out.println("isInterrupted:" + Thread.interrupted() );
        //获取中断标志
        System.out.println("isInterrupted:" + threadOne.isInterrupted());

        threadOne.join();
        System.out.println("main thread id over!");

    }

}
